package com.yanqu.road.server.cmd.chefduel.process2.cross;

import com.yanqu.road.entity.enums.eMailType;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.chefduel.ChefDuelProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.string.StringUtils;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = Protocol.S_CHEF_DUEL2_CAMP_REWARD_SEND_FROM_CROSS, desc = "活动结束阵营奖励补发")
public class ChefDuelCampRewardSendFromCrossCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {

        ChefDuelProto.CrossChefDuelCampRewardSendMsg msg = ChefDuelProto.CrossChefDuelCampRewardSendMsg.parseFrom(yanQuMessage.getBytes());
        for (ChefDuelProto.ChefDuelCampRewardTemp temp : msg.getRankList()) {
            int rank = temp.getRank();
            for (long uid : temp.getUserIdList()) {
                UserInfo userInfoInRAM = UserMgr.getUserInfoInRAM(uid);
                if(userInfoInRAM == null){
                    continue;
                }
                String mailTitle = StringUtils.format(MultipleLanguageMgr.getContent(MailManager.CHEFDUEL_MAIL_TITLE, userInfoInRAM.getLanguage()));
                String mailContent = StringUtils.format(MultipleLanguageMgr.getContent(rank == 1 ? MailManager.CHEFDUEL_MAIL_CONTENT_1 : MailManager.CHEFDUEL_MAIL_CONTENT_2, userInfoInRAM.getLanguage()));
                MailManager.sendMail(uid, eMailType.SYSTEM.getValue(), temp.getReward(), mailContent, mailTitle);
            }
        }
    }
}
